package com.cx.cxapi.util;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

public class Util{
    private static final String ETH1_PATH = "/sys/class/net/eth1";
    public static boolean isEthernet1Exist() {
        String Ethernet1Status = "";
        InputStreamReader isr = null;
        BufferedReader br = null;
        try {
            File file = new File(ETH1_PATH);
            if (file.exists()) {
                return true;
            }

            isr = new InputStreamReader(new FileInputStream(ETH1_PATH));
            br = new BufferedReader(isr);
            String readLine = "";
            while ((readLine = br.readLine()) != null) {
                Ethernet1Status += readLine;
                //  Log.i(TAG, "EthernetCheckExist: Ethernet1Status "+Ethernet1Status);
            }
            br.close();
            isr.close();
            br = null;
            isr = null;
            if (Ethernet1Status != null && !"".equals(Ethernet1Status)) {
                return true;
            }

        } catch (Exception e) {
            // e.printStackTrace();
        }
        return false;
    }

    public static final int execCmd(String paramString) {
        try {
            java.lang.Process localProcess = Runtime.getRuntime().exec("sh");
            Object localObject = localProcess.getOutputStream();
            DataOutputStream localDataOutputStream = new DataOutputStream((OutputStream) localObject);
            String str = String.valueOf(paramString);
            localObject = str + "\n";
            localDataOutputStream.writeBytes((String) localObject);
            localDataOutputStream.flush();
            localDataOutputStream.writeBytes("exit\n");
            localDataOutputStream.flush();
            localProcess.waitFor();
            localObject = localProcess.exitValue();

        } catch (Exception localException) {
            localException.printStackTrace();
        }

        return 0;
    }
}